package com.niit.activity.mapper;

import com.niit.activity.entity.Topic;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TopicMapper {
    @Insert("INSERT INTO tb_topic (content) VALUES (#{content})")
    void addTopic(Topic topic);

    @Select("SELECT * FROM tb_topic")
    List<Topic> getAllTopics();

    @Select("SELECT * FROM tb_topic WHERE id = #{topicId}")
    Topic getTopicById(Long topicId);

    @Select("SELECT content FROM tb_topic WHERE id = #{topicId}")
    String getTopicContentById(Long topicId);

    @Update("UPDATE tb_topic SET topic_num = topic_num + 1 WHERE id = #{topicId}")
    void updateTopicNum(Long topicId);

    @Update("UPDATE tb_topic SET topic_num = topic_num - 1 WHERE id = #{topicId}")
    void decreaseTopicNum(Long topicId);
}